package com.hsc.www.selfLock;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;


@SpringBootApplication
@Configuration
public class App {
    public static void main(String[] args) {
        SpringApplication.run(com.hsc.www.selfLock.App.class, args);
    }












//
//    @Autowired
//    Cache cache;
//
//
//    @Bean
//    public PointcutAdvisor pointcutAdvisor1() {
//        Pointcut pointcut = new AnnotationMatchingPointcut(null, Log.class);
//        Advice advice = new LogMethodInterceptor();
//        return new AbstractPointcutAdvisor() {
//            @Override
//            public Pointcut getPointcut() {
//                return pointcut;
//            }
//
//            @Override
//            public Advice getAdvice() {
//                return advice;
//            }
//        };
//    }
//
//    @Bean
//    public PointcutAdvisor pointcutAdvisor2() {
//        Pointcut pointcut = new AnnotationMatchingPointcut(null, SelfLock.class);
//        Advice advice = new MethodInterceptor() {
//            @Override
//            public Object invoke(MethodInvocation invocation) throws Throwable {
////                System.out.println("SelfLock拦截前");
////                //获取目标类
////                Class<?> targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null);
////                //获取指定方法
////                Method specificMethod = ClassUtils.getMostSpecificMethod(invocation.getMethod(), targetClass);
////                //获取真正执行的方法,可能存在桥接方法
////                final Method userDeclaredMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
////                //获取方法上注
////                SelfLock async = AnnotatedElementUtils.findMergedAnnotation(userDeclaredMethod, SelfLock.class);
////                if (async == null) {
////                    async = AnnotatedElementUtils.findMergedAnnotation(userDeclaredMethod.getDeclaringClass(), SelfLock.class);
////                }
////                String key = async.keyPrefix() + ":" + async.key();
////                boolean isExist = cache.get(key, Object.class) == null ? false : true;
////                if (isExist){
////                    throw new RuntimeException("某某已经存在……");
////                }
////                cache.put(key,1);
////                try {
////                   return invocation.proceed();
////                } catch (Exception e) {
////                   throw e;
////                }finally {
////                    cache.remove(key);
////                    System.out.println("SelfLock拦截后");
////                }
////            }
//        };
//        return new AbstractPointcutAdvisor() {
//            @Override
//            public Pointcut getPointcut() {
//                return pointcut;
//            }
//
//            @Override
//            public Advice getAdvice() {
//                return advice;
//            }
//
//        };
//    }
//
//    @Bean
//    public  Cache cache(){
//        return new MapCache();
//    }

}
